"""
file: test_key_mouse.py
Author: 城下秋草
Date: 2024/11/30
Desc: 键盘鼠标操作
"""
import time

from playwright.sync_api import sync_playwright

playwright = sync_playwright().start()
browser = playwright.chromium.launch(
    headless=False,
    slow_mo=500,
    args=["--window-position=1024,-850"]
)
context = browser.new_context()
context.tracing.start(
    title='秋草测试',
    snapshots=True,
    screenshots=True,
    sources=True
)
page = context.new_page()
page.goto("file:///C:/dev/qiucao/PlayWrightCourse/test.html")

page.get_by_placeholder("请进行输入").click()

page.keyboard.type('a')
page.keyboard.press('ArrowLeft')
page.keyboard.type('b')
page.keyboard.press('KeyC')
page.keyboard.press('Control+A')
page.keyboard.press('Control+C')
page.keyboard.press('Control+V')
page.keyboard.press('Control+V')
page.keyboard.press('Control+V')
page.keyboard.press('Control+V')
page.keyboard.down('Shift')
for i in range(10):
    page.keyboard.press('ArrowLeft')
page.keyboard.up('Shift')
page.keyboard.press('Backspace')

db_click_btn = page.get_by_role('button',name='双击')
db_click_btn.dblclick()
right_btn = page.locator('#right_click_btn')
right_btn.click(button='right')

page.goto('https://demoqa.com/droppable')
drag_btn= page.locator('#draggable')
drop_area = page.locator('div.simple-drop-container > #droppable')

drag_btn.drag_to(drop_area)

page.goto('https://demoqa.com/resizable')

ele = page.locator('div#resizable span')
ele.scroll_into_view_if_needed()

bound = ele.bounding_box()

page.mouse.move(bound['x']+10,bound['y']+10)
page.mouse.down()
page.mouse.move(bound['x']+100,bound['y']+100,steps=100)
page.mouse.up()

time.sleep(3)

context.tracing.stop(path='test.zip')
context.close()
browser.close()
playwright.stop()